from .models import QuestionType,Question,Choice,Answer
from random import sample

#{'选择题'：[5,1],'填空题'：[5,2],...}
#paper_info_obj = {'选择题'：[5,1,[obj]],'填空题'：[5,2,[obj]],...}
#paper_info_pk = {'选择题'：[5,1,[pk,pk]],'填空题'：[5,2],...}
class ProducePaper:
    
    def __init__(self,paper_info):
        
        self.paper_info = paper_info
        self.paper_info_obj = {}
        self.paper_info_pk = {}
        self.produce_paper_obj()

    def produce_paper_obj(self):
        
        for key,value in self.paper_info.copy().items():
        
            q_type = QuestionType.objects.get(
                question_type = key)
            
            q_obj_list = list(q_type.question_set.all())
            
            q_obj_list_sample = sample(q_obj_list,value[0])
            
                    
            self.paper_info_obj[key] = value[:]
            self.paper_info_obj[key].append(q_obj_list_sample)

            q_pk_list_sample =\
            [question.id for question in q_obj_list_sample]
           
                   
            self.paper_info_pk[key] = value[:]
            self.paper_info_pk[key].append(q_pk_list_sample)











            
        
        
        
    
